<?php
$arr = ['李四', 123];
list($name, $age) = $arr;
echo $name, $age;
list(, $ag) = $arr;
echo $ag; // 只想取$age，后面的一个
// list获得关联数组的值
$arr2 = ['name' => '张三', 'age' => 20];
list('name'=> $username, 'age' => $ag) = $arr2;
echo $username, $ag;
echo PHP_EOL.'--------------------------------'.PHP_EOL;

$users = [
    ['name' => '小明', 'age' => 20],
    ['name' => '小李', 'age' => 11],
    ['name' => '小华', 'age' => 21],
];
// 使用while + list遍历数组
while (list('name' => $name, 'age' => $age) = current($users)) {
    echo "name: ${name}, age: {$age}".PHP_EOL;
    // 指针向下滑
    next($users);
}
// 使用foreach遍历数组
echo PHP_EOL.'--------------------------------'.PHP_EOL;
foreach ($users as $key=>$user) {
    print_r($user);
    // 在循环内改变的数组的值
    // $user['age'] += 50;
    $users[$key]['age'] += 50;
    echo $users[$key]['age'];
}
print_r($users);
